import 'package:flutter_deer/generated/json/base/json_convert_content.dart';
import 'package:flutter_deer/index/models/capital_comparison_entity.dart';

CapitalComparisonEntity $CapitalComparisonEntityFromJson(
    Map<String, dynamic> json) {
  final CapitalComparisonEntity idEntity = CapitalComparisonEntity();
  final String? amt1 =
      jsonConvert.convert<String>(json['amt1']);
  if (amt1 != null) {
    idEntity.amt1 = amt1;
  }
  final String? amt2 =
      jsonConvert.convert<String>(json['amt2']);
  if (amt2 != null) {
    idEntity.amt2 = amt2;
  }
  final String? amt_period =
      jsonConvert.convert<String>(json['amt_period']);
  if (amt_period != null) {
    idEntity.amt_period = amt_period;
  }
  final String? dep_bgt_eco_name =
      jsonConvert.convert<String>(json['dep_bgt_eco_name']);
  if (dep_bgt_eco_name != null) {
    idEntity.dep_bgt_eco_name = dep_bgt_eco_name;
  }
  final String? gov_bgt_eco_name = jsonConvert.convert<String>(json['gov_bgt_eco_name']);
  if (gov_bgt_eco_name != null) {
    idEntity.gov_bgt_eco_name = gov_bgt_eco_name;
  }
  final String? exp_func_name = jsonConvert.convert<String>(json['exp_func_name']);
  if (exp_func_name != null) {
    idEntity.exp_func_name = exp_func_name;
  }
  final String? fund_type_name = jsonConvert.convert<String>(json['fund_type_name']);
  if (fund_type_name != null) {
    idEntity.fund_type_name = fund_type_name;
  }
  final String? agency_name = jsonConvert.convert<String>(json['agency_name']);
  if (agency_name != null) {
    idEntity.agency_name = agency_name;
  }
  idEntity.radio = '111';
  return idEntity;
}

Map<String, dynamic> $CapitalComparisonEntityToJson(
    CapitalComparisonEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['amt1'] = entity.amt1;
  data['amt2'] = entity.amt2;
  data['amt_period'] = entity.amt_period;
  data['dep_bgt_eco_name'] = entity.dep_bgt_eco_name;
  data['gov_bgt_eco_name'] = entity.gov_bgt_eco_name;
  data['exp_func_name'] = entity.exp_func_name;
  data['fund_type_name'] = entity.fund_type_name;
  data['agency_name'] = entity.agency_name;
  // data['radio'] = '12';
  // double.tryParse(source)


  // a / b;
  if(entity.amt2 == '0.00') {
     data['radio'] = '100%';
  }
  if (entity.amt2 != null && entity.amt2 != '0.00') {
    data['radio'] = ((double.parse(entity.amt1 ?? '0.00') / double.parse(entity.amt2!))).toStringAsFixed(2) + '%';
  }

  return data;
}

CapitalComparisonPageEntity $CapitalComparisonPageEntityFromJson(
    Map<String, dynamic> json) {
  final CapitalComparisonPageEntity pageEntity = CapitalComparisonPageEntity();
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    pageEntity.total = total;
  }
  final int? size = jsonConvert.convert<int>(json['size']);
  if (size != null) {
    pageEntity.size = size;
  }
  final int? current = jsonConvert.convert<int>(json['current']);
  if (current != null) {
    pageEntity.current = current;
  }
  final int? pages = jsonConvert.convert<int>(json['pages']);
  if (pages != null) {
    pageEntity.pages = pages;
  }
  final List<CapitalComparisonEntity>? records =
      jsonConvert.convert<List<CapitalComparisonEntity>>(json['records']);
  if (records != null) {
    pageEntity.records = records;
  }
  return pageEntity;
}

Map<String, dynamic> $CapitalComparisonPageEntityToJson(
    CapitalComparisonPageEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['total'] = entity.total;
  data['size'] = entity.size;
  data['current'] = entity.current;
  data['records'] = entity.records;
  data['pages'] = entity.pages;
  return data;
}
